home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / amiutils / i_l / irit5 / triv_lib / trinterp.c < prev    next >
C/C++ Source or Header  |  1995-12-30  |  4KB  |  128 lines

  1. /******************************************************************************
  2. * TrivPoly.c - Polygonal approximations of iso surfaces of trivariates.       *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Oct. 94.                          *
  5. ******************************************************************************/
  6.  
  7. #include "geomat3d.h"
  8. #include "triv_loc.h"
  9.  
  10. /*****************************************************************************
  11. * DESCRIPTION:                                                               M
  12. *   Interpolates control points of given trivariate, preserving the order    M
  13. * and continuity of the original trivariate.                     M
  14. *                                                                            *
  15. * PARAMETERS:                                                                M
  16. *   TV:   Trivariate to interpolate its control mesh.                        M
  17. *                                                                            *
  18. * RETURN VALUE:                                                              M
  19. *   TrivTVStruct *: The interpolating trivariate.                            M
  20. *                                                                            M
  21. * KEYWORDS:                                                                  M
  22. *   TrivInterpTrivar, interpolation                                          M
  23. *****************************************************************************/
  24. TrivTVStruct *TrivInterpTrivar(TrivTVStruct *TV)
  25. {
  26.     CagdPointType
  27.     PType = TV -> PType;
  28.     CagdBType
  29.     IsRational = CAGD_IS_RATIONAL_PT(PType);
  30.     int i, j, k, l, m,
  31.     MaxCoord = CAGD_NUM_OF_PT_COORD(PType),
  32.     ULength = TV -> ULength,
  33.     VLength = TV -> VLength,
  34.     WLength = TV -> WLength,
  35.     UOrder = TV -> UOrder,
  36.     VOrder = TV -> VOrder,
  37.     WOrder = TV -> WOrder,
  38.     UVLength = ULength * VLength;
  39.     TrivTVStruct
  40.     *InterpTV = TrivTVCopy(TV);
  41.     CagdRType
  42.         *UKnotVector = TRIV_IS_BSPLINE_TV(TV) ? TV -> UKnotVector
  43.                 : BspKnotUniformOpen(ULength, ULength, NULL),
  44.         *VKnotVector = TRIV_IS_BSPLINE_TV(TV) ? TV -> VKnotVector
  45.                 : BspKnotUniformOpen(VLength, VLength, NULL),
  46.         *WKnotVector = TRIV_IS_BSPLINE_TV(TV) ? TV -> WKnotVector
  47.                 : BspKnotUniformOpen(WLength, WLength, NULL),
  48.     *UNodes = BspKnotNodes(UKnotVector, ULength + UOrder, UOrder),
  49.     *VNodes = BspKnotNodes(VKnotVector, VLength + VOrder, VOrder),
  50.     *WNodes = BspKnotNodes(WKnotVector, WLength + WOrder, WOrder),
  51.     **InterpPoints = InterpTV -> Points,
  52.         **OrigPoints = TV -> Points;
  53.     CagdSrfStruct
  54.     **Srfs = (CagdSrfStruct **) IritMalloc(sizeof(CagdSrfStruct *) *
  55.                                      WLength);
  56.  
  57.     /* Interpolate the WLength surfaces: */
  58.     for (k = 0; k < WLength; k++) {
  59.     int Index = k * UVLength;
  60.     CagdCtlPtStruct *Pt,
  61.          *PtList = NULL;
  62.  
  63.     for (l = 0; l < UVLength; l++, Index++) {
  64.         Pt = CagdCtlPtNew(TV -> PType);
  65.         for (m = !IsRational; m <= MaxCoord; m++)
  66.         Pt -> Coords[m] = OrigPoints[m][Index];
  67.  
  68.         LIST_PUSH(Pt, PtList);
  69.     }
  70.     PtList = CagdListReverse(PtList);
  71.  
  72.     Srfs[k] = BspSrfInterpolate(PtList, ULength, VLength, UNodes, VNodes,
  73.                    UKnotVector, VKnotVector, ULength, VLength,
  74.                    UOrder, VOrder);
  75.  
  76.     CagdCtlPtFreeList(PtList);
  77.     }
  78.  
  79.     /* Interpolate the third, W, dimension. */
  80.     for (i = 0; i < ULength; i++) {
  81.     for (j = 0; j< VLength; j++) {
  82.         int Index = TRIV_MESH_UVW(TV, i, j, 0);
  83.         CagdRType **CrvPoints;
  84.         CagdCrvStruct *Crv;
  85.         CagdCtlPtStruct *Pt,
  86.             *PtList = NULL;
  87.  
  88.         for (k = 0; k < WLength; k++) {
  89.         CagdRType
  90.             **SrfPoints = Srfs[k] -> Points;
  91.  
  92.         Pt = CagdCtlPtNew(TV -> PType);
  93.         for (m = !IsRational; m <= MaxCoord; m++)
  94.           Pt -> Coords[m] = SrfPoints[m][Index];
  95.  
  96.         LIST_PUSH(Pt, PtList);
  97.         }
  98.         PtList = CagdListReverse(PtList);
  99.  
  100.         Crv = BspCrvInterpolate(PtList, WLength, WNodes, WKnotVector,
  101.                     WLength, WOrder, FALSE);
  102.         CrvPoints = Crv -> Points;
  103.  
  104.         for (k = 0; k < WLength; k++) {
  105.         for (m = !IsRational; m <= MaxCoord; m++)
  106.            InterpPoints[m][Index + k * UVLength] = CrvPoints[m][k];
  107.         }
  108.  
  109.         CagdCrvFree(Crv);
  110.     }
  111.     }
  112.  
  113.     IritFree(UNodes);
  114.     IritFree(VNodes);
  115.     IritFree(WNodes);
  116.     if (!TRIV_IS_BSPLINE_TV(TV)) {
  117.     IritFree(UKnotVector);
  118.     IritFree(VKnotVector);
  119.     IritFree(WKnotVector);
  120.     }
  121.     for (i = 0; i < WLength; i++)
  122.     CagdSrfFree(Srfs[i]);
  123.     IritFree(Srfs);
  124.  
  125.     return InterpTV;    
  126. }
  127.  
  128.